#pragma once

//#include "Interfaces.h"
#include "ContourDot.h"
#include "Stroke.h"
#include "DistinctivePoint.h"
#include <vector>
#include <deque>
#include <sstream>

///////////////////////////////////////////////////////////////
// Forward declarations
class Calculator;
namespace Gdiplus { class Graphics; class RectF; };

//////////////////////////////////////////////////////////////
enum VectorParameters
{
	kShowCurves = 0,
	kShowDotCenters,
	kShowDotOuterShapes,
	kShowDotInnerShapes,
	kShowSideColors,
	kShowAllStrokes,
	kShowAllThickCurves,
	kShowAllDistinctivePoints,
	kNumberOfVectorParameters
};

class VectorSketch
{
	typedef std::deque<Stroke> StrokeCollection;
	typedef std::vector<DistinctivePoint> DistinctivePointCollection;
	typedef std::vector<Junction> JunctionCollection;

	float mWidth, mHeight;
	StrokeCollection mStrokes;
	DistinctivePointCollection mDistinctivePoints;
	JunctionCollection mJunctions;
	bool mIsFinal;

	// support of serialization
	float mMaximumStrokeBrightness;

	// support of mouse tracking
	int mHighlightedStrokeIndex;
	RECT mPrevSelectionRect;

	// mode of drawing
	bool mShowCurves, mShowDotCenters;
	bool mShowDotOuterShapes, mShowDotInnerShapes, mShowSideColors,
		mShowAllStrokes;
	bool mShowAllThickCurves, mShowAllDistinctivePoints;

	// support of GDI+
	ULONG_PTR mGdiplusToken;

public:
	VectorSketch(float width, float height);
	~VectorSketch();

	void TraceNewStroke(int x, int y, Calculator&);

	// calculate some parameters 
	void FinalizeStrokes(Calculator&);
	void Finalize(Calculator&);
	
	void AimTheDistinctivePoints(float distanceCriterion);
	bool IsFinal() const;
	void GetStatistics(std::wostringstream& output) const;
	void GetHighlightedInfo(std::wostringstream& output) const;

	void Draw(HDC hdc, RECT rect, float scale, 
		float shiftX, float shiftY) const;
	bool HighlightStroke(float x, float y, float proximity, RECT &outRect);
	void SetParameter(int key, bool value);
	bool IsDrawingAllStrokes() const;

	// saving data
	bool SaveToSVG(std::ostream&) const;
	bool SaveToVML(std::ostream&) const;
	bool SaveToPDF(std::ostream&) const;
	bool SaveToMetafile(const TCHAR* filePath) const;

private:
	void DrawThickCurves(Gdiplus::Graphics&, const Gdiplus::RectF& rect) const;
	void DrawVertexes(Gdiplus::Graphics&, const Gdiplus::RectF& rect, 
		float lineWidth) const;
	void DrawJunctions(Gdiplus::Graphics&, const Gdiplus::RectF& rect, 
		float lineWidth) const;
};

